//
//  photoScrollView.m
//  movie
//
//  Created by 李丹阳 on 15/7/23.
//  Copyright (c) 2015年 李丹阳. All rights reserved.
//

#import "photoScrollView.h"
#import "UIImageView+WebCache.h"

@implementation photoScrollView
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _image = [[UIImageView alloc]initWithFrame:self.bounds];
        _image.contentMode = UIViewContentModeScaleAspectFit;
//        [self addSubview:_image];
//        [_image sd_setImageWithURL:[NSURL URLWithString:_imageUrlStr]];
        self.delegate = self;
        
        self.minimumZoomScale = 1;
        self.maximumZoomScale = 3;
        UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap) ];
        singleTap.numberOfTapsRequired = 1;
        singleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:singleTap];
        [singleTap requireGestureRecognizerToFail:doubleTap];
    }
    
    return self;
}

- (void)doubleTap{
    NSLog(@"doubleTap");
    if (self.zoomScale == 1) {
        [self setZoomScale:3 animated:YES];
    }
    else{
        [self setZoomScale:1 animated:YES];
    }
}

- (void)singleTap{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenNavigationBarNotification" object:nil];
}





- (void)setImageUrlStr:(NSString *)imageUrlStr{
    _imageUrlStr = imageUrlStr;
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [_image sd_setImageWithURL:[NSURL URLWithString:_imageUrlStr]];
    [self addSubview:_image];

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return _image;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
